package com.itheima.admin.service.impl;

import com.itheima.admin.feign.NoteClient;
import com.itheima.admin.feign.ReviewClient;
import com.itheima.admin.service.ContentAuditService;
import com.itheima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 内容审核服务实现
 * 
 * @author itheima
 */
@Slf4j
@Service
public class ContentAuditServiceImpl implements ContentAuditService {

    @Autowired
    private NoteClient noteClient;

    @Autowired
    private ReviewClient reviewClient;

    @Override
    public ResponseResult getPendingNotes(Integer page, Integer size) {
        try {
            return noteClient.getPendingNotes(page, size);
        } catch (Exception e) {
            log.error("调用note-service获取待审核笔记失败", e);
            return ResponseResult.errorResult(500, "获取待审核笔记失败：" + e.getMessage());
        }
    }

    @Override
    public ResponseResult auditNote(Long id, Map<String, Object> params) {
        try {
            Integer status = (Integer) params.get("status");
            String reason = (String) params.get("reason");
            log.info("审核笔记: noteId={}, status={}, reason={}", id, status, reason);
            return noteClient.auditNote(id, params);
        } catch (Exception e) {
            log.error("调用note-service审核笔记失败, noteId={}", id, e);
            return ResponseResult.errorResult(500, "审核笔记失败：" + e.getMessage());
        }
    }

    @Override
    public ResponseResult getPendingReviews(Integer page, Integer size) {
        try {
            return reviewClient.getPendingReviews(page, size);
        } catch (Exception e) {
            log.error("调用review-service获取待审核书评失败", e);
            return ResponseResult.errorResult(500, "获取待审核书评失败：" + e.getMessage());
        }
    }

    @Override
    public ResponseResult auditReview(Long id, Map<String, Object> params) {
        try {
            Integer status = (Integer) params.get("status");
            String reason = (String) params.get("reason");
            log.info("审核书评: reviewId={}, status={}, reason={}", id, status, reason);
            return reviewClient.auditReview(id, params);
        } catch (Exception e) {
            log.error("调用review-service审核书评失败, reviewId={}", id, e);
            return ResponseResult.errorResult(500, "审核书评失败：" + e.getMessage());
        }
    }
}

